package midone.exchangeskill.main.presenter;


import javax.inject.Inject;

import midone.exchangeskill.base.view.Application;
import midone.exchangeskill.bean.IndexGoodsBean;
import midone.exchangeskill.main.contract.MainActivityContract;
import midone.exchangeskill.net.api.ApiManager;
import midone.exchangeskill.net.api.UrlResponse;
import midone.exchangeskill.net.dagger.DaggerApiComponent;

/**
 * Created by NekoNeko on 2016/11/7.
 */

public class MainActivityPresenterImpl implements MainActivityContract.MainActivityPresenter {
    @Inject
    ApiManager mApiManager;
    MainActivityContract.MainActivityView mainActivityView;

    public MainActivityPresenterImpl(MainActivityContract.MainActivityView mainActivityView) {
        this.mainActivityView = mainActivityView;
        DaggerApiComponent.builder().appComponent(Application.getApplication().getAppComponent()).build().inject(this);
    }

    @Override
    public void getIndexGoodsList(String catId, String sort, String pageNum) {
        mainActivityView.showProgress("");
        mApiManager.getIndexGoodsData(catId, sort, pageNum).resCall(new UrlResponse.Call<IndexGoodsBean>() {
            @Override
            public void onResponse() {
                mainActivityView.hideProgress();
            }

            @Override
            public void onSuccess(IndexGoodsBean indexGoodsBean) {
                mainActivityView.onGoodsListSuccess(indexGoodsBean);
            }

            @Override
            public void onFailed(String msg) {
                mainActivityView.onGoodsListFailed(msg);
            }

            @Override
            public void onError(Throwable throwable) {
                mainActivityView.onGoodsListError(throwable);
            }
        });
    }
}
